﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Final
{
    class DBhelp
    {
        private static String conString="server=.;database=Blogs;uid=sa;Pwd=123456";


        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql,sqlConnection);
            
            DataTable dataTable = new DataTable();
            sqlConnection.Open();
            dataAdapter.Fill(dataTable);
            return dataTable;
        }



        public static int UpdateDeleteAdd(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlCommand sqlCommand = new SqlCommand(sql,sqlConnection);
            sqlConnection.Open();
            return sqlCommand.ExecuteNonQuery();
        }




        public static bool LoginRegister(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
            sqlConnection.Open();
            SqlDataReader redaer = sqlCommand.ExecuteReader();
            var dr = redaer.Read();
            return dr;
        }
    }
}
